﻿@{
    Layout = "~/Areas/Master/Views/Shared/_Layout.cshtml";
}

@section Header{
    <script type="text/javascript">
        $(function () {
            $('#Type').click(function () {
                var t = $(this).val();
                if (t == '5') {
                    $('#CodeTableRow').show();
                } else {
                    $('#CodeTableRow').hide();
                }
            });
        });

        function add() {
            $("#addDialog").dialog({
                title: '添加字段',
                modal: true,
                width: 600,
                buttons: [
                    {
                        text: "确定",
                        click: function () {
                            Utils.ajax({
                                url: '@Url.Action("AddField")',
                                data: { 'Code': $('#Code').val(), 'Title': $('#Title').val(), 'Type': $('#Type').val(), 'Length': $('#Length').val(), 'CodeTable': $('#CodeTable').val() },
                                type: 'POST',
                                success: function (d) {
                                    if (d.Result) {
                                        location.reload();
                                    }
                                },
                                error: function (status) { }
                            });
                        }
                    }, {
                        text: '取消',
                        click: function () {
                            $(this).dialog("close");
                        }
                    }
                ]
            });
        }

        function del() {

        }

        function addModel() {
            Utils.confirm('请确认', '确定添加此模型吗？<br /><span style="color:#f00;">该操作将引起数据库增表操作。</span>', function () {
                Utils.ajax({
                    url: '@Url.Action("AddModel")',
                    data: {},
                    type: 'POST',
                    success: function (d) {
                        if (d.Result) {
                            location.href = '@Url.Action("AddStep3")';
                        } else {
                            Utils.alert('消息', d.Message);
                        }
                    },
                    error: function (status) { }
                });
            });
        }
    </script>
}
<div class="panel grid_8">
    <div class="panel-header">
        <span class="i-24 i-sign-post">添加字段</span>
    </div>
    <div class="panel-body">
        <div class="wizard clearfix">
            <ul>
                <li>
                    <a class="ic-16 ic-accept" href="#">第一步：添加表</a>
                </li>
                <li class="current">
                    <a href="javascript:void(0);" class="ic-16 ic-delivery">第二步：字段管理</a>
                </li>
                <li>
                    <a class="ic-16 ic-user" href="javascript:void(0);">第三步：完成</a>
                </li>
            </ul>
        </div>
        <div class="panel-toolbar top clearfix">
            <ul>
                <li><a id="btnAdd" class="ic-16 ic-add" onclick="add();">添加</a></li>
                <li><a id="btnEdit" class="ic-16 ic-edit" onclick="edit();">编辑</a></li>
                <li><a id="btnDel" class="ic-16 ic-cross" onclick="del();">删除</a></li>
            </ul>
        </div>
        <div class="dataTables_wrapper">
            <table class="datatable-fn table">
                <thead>
                    <tr>
                        <th style="width: 30px;"><input type="checkbox" onchange="Utils.checkAll(this.checked);" /></th>
                        <th style="width: 200px;">字段编码</th>
                        <th style="width: auto;">字段名称</th>
                        <th style="width: 80px;">字段类型</th>
                        <th style="width: 80px;">字段长度</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model)
                    {
                        <tr>
                            <td class="center"><input class="cboItem" type="checkbox" value="@item.Id" /></td>
                            <td class="center">@item.Code</td>
                            <td class="center">@item.Title</td>
                            <td class="center">@item.Type</td>
                            <td class="center">@item.Length</td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
        <div class="panel-toolbar bottom clearfix">
            <ul>
                <li><a id="btnAdd2" class="ic-16 ic-add" onclick="add();">添加</a></li>
                <li><a id="btnEdit2" class="ic-16 ic-edit" onclick="edit();">编辑</a></li>
                <li><a id="btnDel2" class="ic-16 ic-cross" onclick="del();">删除</a></li>
            </ul>
        </div>
        <form class="form" method="post" action="@Url.Action("AddModel")">
            <div class="button-row">
                <input type="button" value="上一步" class="btn gray left" />
                <input type="button" value="下一步" class="btn green" onclick="addModel();" />
            </div>
        </form>
    </div>
</div>
<div id="addDialog" class="hide">
    <div class="form-inline form">
        <div class="form-row">
            <label>字段编码</label>
            <div class="form-item large">
                <input id="Code" class="textinput" type="text" /><input type="hidden" id="ID" />
            </div>
        </div>
        <div class="form-row">
            <label>字段名称</label>
            <div class="form-item large">
                <input id="Title" class="textinput" type="text" />
            </div>
        </div>
        <div class="form-row">
            <label>字段类型</label>
            <div class="form-item large">
                <select id="Type">
                    <option value="0">文本值</option>
                    <option value="1">整数值</option>
                    <option value="2">是否值</option>
                    <option value="3">小数值</option>
                    <option value="4">日期值</option>
                    <option value="5">选项值</option>
                </select>
            </div>
        </div>
        <div id="CodeTableRow" class="form-row hide">
            <label>选项值</label>
            <div class="form-item large">
                <textarea id="CodeTable" style="overflow-y:hidden;"></textarea>
            </div>
        </div>
        <div class="form-row">
            <label>字段长度</label>
            <div class="form-item large">
                <input id="Length" class="textinput" type="text" />
            </div>
        </div>
    </div>
</div>